package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.MarketCollectExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketCollectMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月28日 13:45
 */
public class AdminCollectServiceimpl implements AdminCollectService {

    @Override
    public CommonData query(Integer page, Integer limit, String sort, String order) {
        MarketCollectMapper mapper = MyBatisUtil.getMapper(MarketCollectMapper.class);
        PageHelper.startPage(page, limit);
        MarketCollectExample marketCollectExample = new MarketCollectExample();
        marketCollectExample.setOrderByClause(sort + " " + order);
        List<MarketCollect> marketCollects = mapper.selectByExample(marketCollectExample);
        PageInfo<MarketCollect> marketCollectPageInfo = new PageInfo<>(marketCollects);
        return CommonData.data(marketCollectPageInfo);
    }

    @Override
    public List<MarketCollect> selectByUserId(Integer userId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketCollectMapper mapper = sqlSession.getMapper(MarketCollectMapper.class);
        List<MarketCollect> marketCollects = mapper.selectByUserId(userId);
        for (MarketCollect marketCollect : marketCollects) {
            System.out.println(marketCollect);
        }
        sqlSession.close();
        return marketCollects;
    }

    @Override
    public List<MarketCollect> selectByValueId(Integer valueId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketCollectMapper mapper = sqlSession.getMapper(MarketCollectMapper.class);
        List<MarketCollect> marketCollects = mapper.selectByValueId(1110019);
        for (MarketCollect marketCollect : marketCollects) {
            System.out.println(marketCollect);
        }
        sqlSession.close();
        return marketCollects;
    }
}
